package com.example.composeplayground.screens.main

import android.app.Activity
import android.webkit.PermissionRequest
import android.webkit.WebChromeClient
import android.webkit.WebView
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.viewinterop.AndroidView

@Preview
@Composable
fun MeScreen() {
    AndroidView(
        factory = { context ->
            WebView(context).apply {
                settings.javaScriptEnabled = true
                settings.domStorageEnabled = true

                webChromeClient = object : WebChromeClient() {
                    override fun onPermissionRequest(request: PermissionRequest) {
                        // 在主线程处理权限请求
                        (context as? Activity)?.runOnUiThread {
                            request.grant(request.resources)
                        }
                    }
                }
            }
        },
        update = { webView ->
            webView.loadUrl("https://fe.dogzhang.com/index2.html")
        }
    )
}